package website.seamonster.ethegg.dataobject;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.*;
import java.sql.Timestamp;
import java.util.Objects;

/**
 * Created by 罗海量
 * 2018-07-19 21:31
 */
@Entity
@Table(name = "sys_chicken")
@Slf4j
@Data
@DynamicInsert
@DynamicUpdate
public class Chicken {

    private long id;
    private String chickenName;
    private String userId;
    private int bornNum;
    private boolean isAlive;
    private Timestamp createTime;
    private long version;

    @Id
    @Column(name = "ID")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    @Basic
    @Column(name = "CHICKEN_NAME")
    public String getChickenName() {
        return chickenName;
    }

    public void setChickenName(String chickenName) {
        this.chickenName = chickenName;
    }

    @Basic
    @Column(name = "USER_ID")
    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    @Basic
    @Column(name = "BORN_NUM")
    public int getBornNum() {
        return bornNum;
    }

    public void setBornNum(int bornNum) {
        this.bornNum = bornNum;
    }

    @Basic
    @Column(name = "IS_ALIVE")
    public boolean isAlive() {
        return isAlive;
    }

    public void setAlive(boolean alive) {
        isAlive = alive;
    }

    @Basic
    @Column(name = "CREATE_TIME")
    public Timestamp getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Timestamp createTime) {
        this.createTime = createTime;
    }

    @Basic
    @Column(name = "VERSION")
    public long getVersion() {
        return version;
    }

    public void setVersion(long version) {
        this.version = version;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Chicken chicken = (Chicken) o;
        return id == chicken.id &&
                bornNum == chicken.bornNum &&
                isAlive == chicken.isAlive &&
                version == chicken.version &&
                Objects.equals(chickenName, chicken.chickenName) &&
                Objects.equals(userId, chicken.userId) &&
                Objects.equals(createTime, chicken.createTime);
    }

    @Override
    public int hashCode() {

        return Objects.hash(id, chickenName, userId, bornNum, isAlive, createTime, version);
    }
}
